package org.wu.framework.lazy.orm.core.source.postgresql;

import lombok.Data;
import org.wu.framework.core.NormalUsedString;
import org.wu.framework.core.utils.ObjectUtils;
import org.wu.framework.lazy.orm.core.persistence.conf.LazyTableFieldEndpoint;
import org.wu.framework.lazy.orm.core.persistence.conf.field.AbstractLazyTableFieldEndpoint;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableField;

/**
 * mysql Java字段转换成mysql column对象处理
 */
@Data
public class PostgresqlColumnEndpoint extends AbstractLazyTableFieldEndpoint {

    /**
     * @return 行sql
     * description 创建SQL column
     * "name" varchar(100) COLLATE "pg_catalog"."default",
     * @author Jiawei Wu
     * @date 2020/12/31 9:19 下午
     **/
    @Override
    public String columnSQL() {
        return NormalUsedString.QUOTE+getColumnName() +NormalUsedString.QUOTE+ NormalUsedString.SPACE +
                getColumnType() + NormalUsedString.SPACE +
                (
                        isNotNull() ?
                                NormalUsedString.SPACE + NormalUsedString.NOT + NormalUsedString.SPACE + NormalUsedString.NULL + NormalUsedString.SPACE :
                                NormalUsedString.SPACE
                )
//                + (
//                        ObjectUtils.isEmpty(getDefaultValue()) ?
//                                NormalUsedString.SPACE :
//                                NormalUsedString.SPACE + NormalUsedString.DEFAULT + NormalUsedString.SPACE + getDefaultValue() + NormalUsedString.SPACE)
//                + NormalUsedString.SPACE + getExtra() + NormalUsedString.SPACE
                ;
    }
    /**
     * 数据库列类型
     * @return
     */
    @Override
    public String getColumnType() {
        return ObjectUtils.isEmpty(super.getColumnType()) ? LazyTableField.FieldType.getPostgresTypeByClass(super.getClazz()) : super.getColumnType();
    }
    @Override
    public LazyTableFieldEndpoint clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return super.toString();
    }
}
